<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <span>pollingClient</span>
  <button onclick="javascript:history.back()">back</button>

  <script>
    function createXHR() {
      if (typeof XMLHttpRequest != 'undefined') {
        return new XMLHttpRequest();
      } else if (typeof ActiveXObject != 'undefined') {
        if (typeof arguments.callee.activeXString != "string") {
          var versions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0",
              "MSXML2.XMLHttp"
            ],
            i, len;
          for (i = 0, len = versions.length; i < len; i++) {
            try {
              new ActiveXObject(versions[i]);
              arguments.callee.activeXString = versions[i];
              break;
            } catch (ex) {

            }
          }
        }
        return new ActiveXObject(arguments.callee.activeXString);
      } else {
        throw new Error("no xhr object available");
      }
    }

    function longPolling(url, method, data) {
      method = method || 'get';
      data = data || null;
      var xhr = createXHR();
      xhr.onreadystatechange = function () {
        if (xhr.readyState == 4) {
          if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) {
            console.log(xhr.responseText);
          } else {
            console.log("fail");
          }
          longPolling(url, method, data);
        }
      };
      xhr.open(method, url, true);
      xhr.send(data);
    }
    longPolling('http://localhost:8088/longpolling', 'get');
  </script>
</body>

</html>
